package sjtu.ist.warehouse4ws.junit;

import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import sjtu.ist.warehouse4ws.dao.ShiroPermissionDao;
import sjtu.ist.warehouse4ws.dao.ShiroRoleDao;
import sjtu.ist.warehouse4ws.dao.ShiroUserDao;
import sjtu.ist.warehouse4ws.jcr.RepositoryMoudl;
import sjtu.ist.warehouse4ws.jcr.Testjcr;
import sjtu.ist.warehouse4ws.model.ModelFilePojo;
import sjtu.ist.warehouse4ws.model.ShiroPermission;
import sjtu.ist.warehouse4ws.model.ShiroRole;
import sjtu.ist.warehouse4ws.model.ShiroUser;
import sjtu.ist.warehouse4ws.service.ShiroPermissionService;
import sjtu.ist.warehouse4ws.service.ShiroRoleService;
import sjtu.ist.warehouse4ws.service.ShiroUserService;
import sjtu.ist.warehouse4ws.tool.FileIO;



public class TestDao {
	
	private ShiroUserDao shiroUserDao;
	private ShiroUserService shiroUserService;
	private ShiroRoleService shiroRoleService;
	private ShiroRoleDao shiroRoleDao;
	private ShiroPermissionService shiroPermissionService;
	private ShiroPermissionDao shiroPermissionDao;
	private Testjcr testjcrService;
	private RepositoryMoudl repositoryMoudlService;
	@Before
	public void setUp() throws Exception {
		String path = "WebContent/WEB-INF/applicationContext.xml";
		ApplicationContext context = new FileSystemXmlApplicationContext(path);
		shiroUserDao = (ShiroUserDao) context.getBean("shiroUserDao");
		shiroUserService = (ShiroUserService) context.getBean("shiroUserService");
		shiroRoleDao = (ShiroRoleDao) context.getBean("shiroRoleDao");
		shiroRoleService = (ShiroRoleService) context.getBean("shiroRoleService");
		shiroPermissionDao = (ShiroPermissionDao) context.getBean("shiroPermissionDao");
		shiroPermissionService = (ShiroPermissionService) context.getBean("shiroPermissionService");
		testjcrService = (Testjcr) context.getBean("testjcrService");
		repositoryMoudlService = (RepositoryMoudl) context.getBean("repositoryMoudlService");
		
	}
//@Test
public void testjackrabbit(){
	//testjcrService.testjcr();
	testjcrService.testjcrVersion();
}
@Test
public void testworkspace(){
	String companyId="0";
	String modelType="1";
	repositoryMoudlService.createWorkSpace(companyId);
	repositoryMoudlService.addModelNode(companyId,modelType);
	/*String docpath="D:/demo2";
	FileIO fio=new FileIO();
	ModelFilePojo mfp=fio.getAllModelData(docpath);
	repositoryMoudlService.importAllModel(companyId, modelType, mfp);
	System.out.print("------------导入模型成功");*/
	
	
	
	//test
	repositoryMoudlService.testVersions(companyId, modelType);

	//String ver=repositoryMoudl.getVersion(companyId, modelType);
	//System.out.print(ver);
	//System.out.print(repositoryMoudlService.getNodesNames("0").get(0));
}
//@Test
	public void test(){
		ShiroUser user=shiroUserDao.findUser("cqd");
		System.out.println(user.getPassword());
	}
//@Test
public void testa(){
	ShiroUser user=shiroUserDao.getUser(1);
	System.out.println(user.getUsername());
}
//@Test
public void testSave(){
	ShiroUser user=new ShiroUser();   //开个空间很重要
	user.setCompanyId(6);
	user.setPassword("admin");
	user.setUsername("admin");
	shiroUserService.saveShiroUser(user);
	System.out.print("-----------"+"success");
	
}
//@Test
public void testservice(){
	ShiroUser user=shiroUserService.findUser("cqd");
	System.out.println("----------"+user.getPassword());
}

//@Test
public void testservice1(){
	ShiroUser user=shiroUserService.getUser(1);
	System.out.println("----------"+user.getPassword());
}
//@Test
public void testSave1(){
	ShiroRole role=new ShiroRole();   //开个空间很重要
	role.setDescription("user");
	role.setRolename("user");

	
	ShiroPermission permission=new ShiroPermission();
	permission.setPermission("model:wadl");
	
	role.getShiroPermissions().add(permission);
	permission.getShiroRole().add(role);
	
	shiroRoleService.saveShiroRole(role);
	shiroPermissionService.saveShiroPermission(permission);

	System.out.print("-----------"+"success");
	
}


}
